package com.simple.datax.web;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.simple.datax.bo.IDataxDictionaryBO;
import com.simple.datax.bo.IDataxParseRawMsgBO;
import com.simple.datax.bo.IDataxSendRawMsgBO;
import com.simple.datax.vo.DataxParseRawMsgVO;
import com.simple.datax.vo.DataxSendRawMsgVO;
import com.simple.util.common.Constants;
import com.simple.util.object.PageInfoBean;

@Controller
public class MessageQueryController extends AbstractDataxBaseController{
	private final static String JSP_PATH = "_MessageQuery";
	@Autowired
	private IDataxParseRawMsgBO dataxParseRawMsgBO;
	@Autowired
	private IDataxSendRawMsgBO dataxSendRawMsgBO;
	@Autowired
	private IDataxDictionaryBO dataxDictionaryBO;

	@RequestMapping("/messageQueryReceive")
	public String MessageReceive(
			@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
			@RequestParam(value = "fcRecvRawMsgIdSelect", required = false) String fcRecvRawMsgIdSelect,
			@RequestParam(value = "fcMessageIdSelect", required = false) String fcMessageIdSelect,
			@RequestParam(value = "fcSenderSelect", required = false) String fcSenderSelect,
			@RequestParam(value = "fcReceiverSelect", required = false) String fcReceiverSelect,
			@RequestParam(value = "fromDateSelect", required = false) String fromDateSelect,
			@RequestParam(value = "toDateSelect", required = false) String toDateSelect,
			HttpServletRequest request, HttpServletResponse response) {
		
		final PageInfoBean pageInfoBean = new PageInfoBean(pageNo);
		final List<DataxParseRawMsgVO> dataxParseRawMsgVOList = dataxParseRawMsgBO
				.findDataxParseRawMsgVOByPage(pageInfoBean, fcRecvRawMsgIdSelect,
						fcMessageIdSelect, fcSenderSelect, fcReceiverSelect,fromDateSelect,toDateSelect);
		final Map<String, String> catagoryMessageStatusMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGESTATUS);
		request.setAttribute("catagoryMessageStatusMap",catagoryMessageStatusMap);
		request.setAttribute("dataxParseRawMsgVOList",dataxParseRawMsgVOList);
		final String pageInfo = super.generatePageInfo(request, response,
				pageInfoBean, "goPage");
		request.setAttribute("pageInfo", pageInfo);
		request.setAttribute("pageNo", pageNo);
		request.setAttribute("fcRecvRawMsgIdSelect", fcRecvRawMsgIdSelect);
		request.setAttribute("fcMessageIdSelect", fcMessageIdSelect);
		request.setAttribute("fcSenderSelect", fcSenderSelect);
		request.setAttribute("fcReceiverSelect", fcReceiverSelect);
		request.setAttribute("fromDateSelect", fromDateSelect);
		request.setAttribute("toDateSelect", toDateSelect);
		
		return getJspPath("messagequery_receive");
	}

	@RequestMapping("/messageQuerySend")
	public String MessageSend(
			@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
			@RequestParam(value = "fcRecvRawMsgIdSelect", required = false) String fcRecvRawMsgIdSelect,
			@RequestParam(value = "fcMessageIdSelect", required = false) String fcMessageIdSelect,
			@RequestParam(value = "fcSenderSelect", required = false) String fcSenderSelect,
			@RequestParam(value = "fcReceiverSelect", required = false) String fcReceiverSelect,
			@RequestParam(value = "fromDateSelect", required = false) String fromDateSelect,
			@RequestParam(value = "toDateSelect", required = false) String toDateSelect,
			HttpServletRequest request, HttpServletResponse response) {
		
		final PageInfoBean pageInfoBean = new PageInfoBean(pageNo);
		final List<DataxSendRawMsgVO> dataxSendRawMsgVOList = dataxSendRawMsgBO
				.findDataxSendRawMsgVOByPage(pageInfoBean, fcRecvRawMsgIdSelect,
						fcMessageIdSelect, fcSenderSelect, fcReceiverSelect,
						fromDateSelect,toDateSelect);
		final Map<String, String> catagoryMessageStatusMap = dataxDictionaryBO
				.findMapByCatagory(Constants.TRANS_PROPERTY_FICATAGORY_MESSAGESTATUS);
		request.setAttribute("catagoryMessageStatusMap",catagoryMessageStatusMap);
		request.setAttribute("dataxSendRawMsgVOList",dataxSendRawMsgVOList);
		final String pageInfo = super.generatePageInfo(request, response,
				pageInfoBean, "goPage");
		request.setAttribute("pageInfo", pageInfo);
		request.setAttribute("pageNo", pageNo);
		request.setAttribute("fcRecvRawMsgIdSelect", fcRecvRawMsgIdSelect);
		request.setAttribute("fcMessageIdSelect", fcMessageIdSelect);
		request.setAttribute("fcSenderSelect", fcSenderSelect);
		request.setAttribute("fcReceiverSelect", fcReceiverSelect);
		request.setAttribute("fromDateSelect", fromDateSelect);
		request.setAttribute("toDateSelect", toDateSelect);

		return getJspPath("messagequery_send");
	}
	
	@Override
	protected String getBaseJspPath() {
		return JSP_PATH;
	}

}
